package com.juyu.miliao.api.controller.luckdraw;

import com.juyu.miliao.api.domain.LuckDrawLog;
import com.juyu.miliao.api.domain.LuckDrawPrize;
import com.juyu.miliao.api.service.PrizeService;
import com.juyu.miliao.common.domain.Subject;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 抽奖控制层
 * @Auther: 卜加超
 * @Date: 2019/7/11 13:38
 * @Description:
 */
@RestController
@RequestMapping("prize")
public class PrizeController {
    @Resource
    private PrizeService prizeService;

    /**
     * 获取奖品列表
     * @return
     */
    @GetMapping("/list")
    public List<LuckDrawPrize> getPrizeList(){
        return prizeService.getPrizeList();
    }

    /**
     * 获取抽奖次数
     * @param token
     * @return
     */
    @GetMapping("/prizeNum")
    public int getLuckDrawNum(Authentication token){
       Subject subject = (Subject)token.getPrincipal();
       return prizeService.getLuckDrawNum(subject.getId());
    }

    /**
     * 开始抽奖
     */
    @GetMapping("/luckDraw")
    public LuckDrawPrize getPrize(Authentication token, HttpServletRequest request){
        Subject subject = (Subject)token.getPrincipal();
        return prizeService.getLuckDrawPrize(subject.getId(),request);
    }

    /**
     * 获取中奖列表
     * @param token
     * @return
     */
    @GetMapping("/luckDrawList")
    public List<LuckDrawLog> getLuckDrawList(Authentication token){
        Subject subject = (Subject)token.getPrincipal();
        return prizeService.getLuckDrawList(subject.getId());
    }

    /**
     * 获取个人中奖列表
     * @param token
     * @return
     */
    @GetMapping("/luckList/{type}")
    public List<LuckDrawLog> getLuckDrawListByUserId(Authentication token, @PathVariable("type")int type){
        Subject subject = (Subject)token.getPrincipal();
       return  prizeService.getLuckDrawListByUserId(subject.getId(),type);
    }

    /**
     * 取消兑换奖品
     * @param token
     * @param drawId
     */
    @GetMapping("/cancelLuckDraw/{drawId}")
    public void cancelLuckDraw(Authentication token,@PathVariable()int drawId ){
        Subject subject = (Subject)token.getPrincipal();
        prizeService.cancelLuckDraw(subject.getId(),drawId);
    }
    @GetMapping("/searchBeans")
    public void UserSearchForBeans(Authentication token){
        Subject subject = (Subject)token.getPrincipal();
        prizeService.getSearchForBeans(subject.getId());
    }
}
